package com.food.controller;

import com.food.common.Result;
import com.food.model.Food;
import com.food.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/food")
public class FoodController {

    @Autowired
    private FoodService foodService;

    @GetMapping("/search")
    public Result<List<Food>> searchFoods(@RequestParam String keyword) {
        List<Food> foods = foodService.searchFoods(keyword);
        return Result.success(foods);
    }

    @GetMapping("/{foodId}")
    public Result<Food> getFoodById(@PathVariable Integer foodId) {
        Food food = foodService.getFoodById(foodId);
        return Result.success(food);
    }

    @GetMapping("/category/{category}")
    public Result<List<Food>> getFoodsByCategory(@PathVariable String category) {
        List<Food> foods = foodService.getFoodsByCategory(category);
        return Result.success(foods);
    }

    @GetMapping("/categories")
    public Result<List<String>> getAllCategories() {
        List<String> categories = foodService.getAllCategories();
        return Result.success(categories);
    }
} 